package com.ab;

/**
хуй хуй жопа жопа хуй
 */
public class DeadLockPrimitive {
    public static void main(String[] args) {
        //sobjects to block
        final String blockMe1 = "First string is occupied by";
        final String blockMe2 = "Second string is occupied by";

        Thread firstBlocker = new Thread() {
            public void run() {
                synchronized (blockMe1) {
                    System.out.println(blockMe1);
                    System.out.println("first thread");

                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {

                    }
                    synchronized (blockMe2) {
                        System.out.println(blockMe2);
                        System.out.println("first thread");
                    }
                }

            }
        };

        Thread secondBlocker = new Thread() {
            public void run() {
                synchronized (blockMe2) {
                    System.out.println(blockMe2);
                    System.out.println("second thread");

                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {

                    }
                    synchronized (blockMe1) {
                        System.out.println(blockMe1);
                        System.out.println("second thread");
                    }
                }
            }
        };
        firstBlocker.start();
        secondBlocker.start();
    }


}
